<template>
  <div>
    <!-- 面包屑导航条 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card class="box-card">
      <el-form :model="searchForm" class="demo-form-inline" >
        <el-row :gutter="20">
          <el-form-item>
            <el-input style="width:150px;height:30px;" placeholder="姓名" v-model="searchForm.showName"></el-input>
            <el-select   style="width:150px;height:30px; margin-left: 10px" v-model="searchForm.status" placeholder="选择角色">
              <el-option label="房东" :value="0"></el-option>
              <el-option label="中介" :value="1"></el-option>
              <el-option label="租户" :value="2"></el-option>
            </el-select>
            <el-input style="width:150px;height:30px;  margin-left: 10px" placeholder="手机号" v-model="searchForm.mobile"></el-input>
            <el-button style=" margin-left: 10px" @click="searchList" plain type="info">搜索</el-button>
            <el-button @click="searchEmpty" plain type="info">清空</el-button>
          </el-form-item>
        </el-row>
      </el-form>

      <el-table
        :data="tableList"
        stripe
        style="width: 100%">
        <el-table-column
          type="index"
          width="50">
        </el-table-column>
        <el-table-column
          label="用户名"
          prop="loginName"
          width="120">
        </el-table-column>
        <el-table-column
          label="姓名"
          prop="showName"
          width="120">
        </el-table-column>
        <el-table-column
          label="角色"
          width="120">
          <template slot-scope="scope">
            {{scope.row.status | statusFit}}
          </template>
        </el-table-column>
        <el-table-column
          label="年龄"
          prop="age"
          width="120">
        </el-table-column>
        <el-table-column
          label="性别" width="120">
          <template slot-scope="scope">
            {{scope.row.sex | sexFit}}
          </template>
        </el-table-column>
        <el-table-column
          label="手机号"
          prop="mobile" width="180">
        </el-table-column>
        <el-table-column
          label="邮箱"
          prop="email" width="180">
        </el-table-column>
        <el-table-column
          label="注册日期"
          prop="createTime" width="160">
          <template slot-scope="scope">
            {{scope.row.createTime | dateFit('YYYY/MM/DD')}}
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        :current-page="page.currentPage"
        :page-size="page.pageSize"
        :page-sizes="[5, 10, 20, 40]"
        :total="total"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>

    </el-card>
  </div>
</template>

<script>
    export default {
      name: "UserList",
      data() {
        return {
          searchForm: {},
          tableList: [],
          page: {
            currentPage: 0,
            pageSize: 5
          },
          total: 0,
          auth:{token:null},
        }
      },
      methods: {
        searchEmpty: function () {//清空
          this.searchForm = {}
        },
        searchList: function () {//用户列表
          this.$http.post("house-user/user/list/" + this.page.currentPage + "/" + this.page.pageSize, this.searchForm).then((res) => {
            this.tableList = res.data.result.list
            this.total = res.data.result.total
          })
        },
        handleSizeChange: function (val) {
          this.page.pagesize = val;
          this.searchList();
        },
        handleCurrentChange: function (val) {
          this.page.pagenum = val;
          this.searchList();
        },
        crearUserForm: function () {
          //清空数据
          this.userForm = {}
        },
      },
      filters: {
        sexFit: function (v1) {
          if (v1 == '0') return '男'
          if (v1 == '1') return '女'
        },
        statusFit: function (val) {
          if(val==0) return "房东"
          if(val==1) return "中介"
          if(val==2) return "用户"
        }
      },
      mounted() {
        this.searchList();
      }
    }
</script>

<style scoped>

</style>
